var WarnForm = function () {
  var template = /* html */ `
    <div class="warn-form" v-loading.fullscreen.lock="loading">
      <el-form label-width="auto" size="medium">
        <el-form-item required label="警报类型">
          <sys-autocomplete v-model="warnForm.typeName" class="form-input" :options="warnTypeList">
          </sys-autocomplete>
        </el-form-item>
        <el-form-item required label="警报代码">
          <el-input v-model="warnForm.alarmCode" class="form-input"></el-input>
        </el-form-item>
        <el-form-item required label="警报描述">
          <el-input v-model="warnForm.codeDescribe" class="form-input"></el-input>
        </el-form-item>
        <el-form-item label="看板是否显示">
          <el-select v-model="warnForm.isShow" class="form-input">
            <el-option v-for="item in isShowList" :key="item.value" :value="item.value" :label="item.label">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div style="text-align:center">
        <el-button size="medium" type="primary" @click="addWarn">新增</el-button>
      </div>
    </div>
  `;

  return {
    props: {
      type: {
        type: String,
        default: 'add'
      },

      warn: {
        type: Object,
        default: function () {
          return null;
        }
      },

      warnTypeList: {
        type: Array,
        required: true
      }
    },

    data: function () {
      return {
        loading: false,
        warnForm: new WarnFormModel(this.warn),
        isShowList: i18n.getDropDown('machineRepair.warnSetting.isShow', [1, 2])
      };
    },

    methods: {
      addWarn: function () {
        var warnForm = this.warnForm;
        var code = warnForm.checkValid();
        if (code !== '') {
          var msg = i18n.getMsg(`machineRepair.warnSetting.error.${code}`);
          this.$alert(msg, '信息');
          return;
        }

        var postData = warnForm.getObject();
        this.loading = true;
        var self = this;
        ajaxRequest('equipment/addEquipmentAlarmCode', {
          jsonArray: JSON.stringify([postData])
        }).then(function () {
          self.loading = false;
          self.$alert('警报设置新增成功', '信息', {
            callback: function () {
              self.$emit('add-success', postData);
            }
          });
        }).catch(function () {
          self.loading = false;
        });
      }
    },

    components: {
      SysAutocomplete: SysAutocomplete
    },

    template: template
  };
}();
